//
//  SAPCityViewController.m
//  CarsHome
//
//  Created by dapeng on 15/12/12.
//  Copyright © 2015年 dapeng. All rights reserved.
//

#import "SAPCityViewController.h"
#import "SAPWeatherViewController.h"
#import "SAPAreaViewController.h"
@interface SAPCityViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITextField            *cityTxt;
@property (nonatomic, retain) NSArray                *pnArr;
@property (nonatomic, retain) NSMutableArray         *pcArr;
@property (nonatomic, retain) NSArray                *cnArr;
@property (nonatomic, retain) NSMutableArray         *ccArr;
@property (nonatomic, retain) NSDictionary           *allDic;
@property (nonatomic, retain) NSMutableDictionary    *linkCodeDic;
@property (nonatomic, retain) UITableView            *tableView;
@property (nonatomic, retain) UITapGestureRecognizer *tap;
@end

@implementation SAPCityViewController
- (void)dealloc {
    [_cityTxt release];
    [_pnArr release];
    [_pcArr release];
    [_cnArr release];
    [_allDic release];
    [_linkCodeDic release];
    [_tableView release];
    [_tap release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initDataSource] ;
    [self downloadData] ;
    [self tableViews];
}
-(void)initDataSource {
    self.pnArr = [[NSArray alloc] init] ;
    self.pcArr = [[NSMutableArray alloc] init] ;
    self.cnArr = [[NSArray alloc] init] ;
    self.ccArr = [[NSMutableArray alloc] init] ;
    
    self.allDic = [[NSMutableDictionary alloc] init] ;
    self.linkCodeDic = [[NSMutableDictionary alloc] init] ;
}
-(void)tableViews {
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCellIndentifier"];
    [self.view addSubview:self.tableView];
    [_tableView release];
}
-(void)downloadData {
    self.allDic = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"code_1" ofType:@"plist"]];
    self.pnArr = self.allDic.allKeys;
}
#pragma mark - UITableViewDelegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"UITableViewCellIndentifier"];
    cell.textLabel.text = self.pnArr[indexPath.row];
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.pnArr.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    NSDictionary *cityDic = [[NSDictionary alloc] init];
    cityDic = self.allDic.allValues[indexPath.row];
    SAPAreaViewController *areaVC = [[SAPAreaViewController alloc] init];
    areaVC.cnDic = cityDic;
    [self.navigationController pushViewController:areaVC animated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
